package de.unistuttgart.iaas.interaction.skype.services;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import org.apache.log4j.Logger;
//import org.apache.log4j.PropertyConfigurator;

import java.io.IOException;
//import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;

import de.unistuttgart.iaas.interaction.skype.ProcessMessage;
import de.unistuttgart.iaas.interaction.skype.ReceiveMessage;
import de.unistuttgart.iaas.interaction.skype.Register;
import de.unistuttgart.iaas.interaction.skype.SendMessage;

public class SkypeAutoRun extends HttpServlet{

	private static final int RECEIVE_PERIOD = 1*60*1000;
	private static final int REGISTER_PERIOD = 2*60*1000;
	private static final int PERIOD = 2*60*1000;
	
	public void init()
	{
			
		final String config = getServletConfig().getInitParameter("ConfigFile");
	
		
		Timer timer = new Timer(true);
			
		/**TimerTask for SendMessage()*/
		timer.schedule(new TimerTask()
		{
			public void run()
			{
				try
				{	
					/** */
					ReceiveMessage.ReceiveMessage(config);
	
				}catch(Exception e){}
			}
		},0,RECEIVE_PERIOD);
			
		/**TimerTask for register()*/
		timer.schedule(new TimerTask()
		{
			public void run()
			{
				try
				{					
					Register.register(config);

				}catch(Exception e){}
			}
		},0,REGISTER_PERIOD);

		/**TimerTask for sendMessage()*/
		timer.schedule(new TimerTask()
		{
			public void run()
			{
				try
				{					
					SendMessage.sendMessage(config);

				}catch(Exception e){}
			}
		},0,PERIOD);
		
		/**TimerTask for ProcessMessage()*/
		timer.schedule(new TimerTask()
		{
			public void run()
			{
				try
				{					
					ProcessMessage.ProcessMessage(config);

				}catch(Exception e){}
			}
		},0,PERIOD);
	}


//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
        ServletException, IOException {
}

//Clean up resources
public void destroy() 
{
}
	

}
